<?php
namespace app\oem\controller;
use think\Controller;
use think\Db;
use app\common\controller\OemBaseController;

class Bluesea extends OemBaseController
{
	public function indexs(){
		if(input("begin_balance")){
			$where['b.count_balance']=['>=',input("begin_balance")];
		}
		if(input("end_balance")){
			$where['b.count_balance']=['<=',input("end_balance")];
		}
		
		if(input('mobile')){$where['a.mobile'] = input('mobile');} 
		if(input('count')){$where['b.count'] = input('count');}
		if(input('count_balance')){$where['b.count_balance'] = input('count_balance');}
		
		$score = db('log_user_score')->where('order_type',14)->group('u_id')->field('u_id,sum(balance) as count_balance,count(new_user_id) as count')->buildSql();
		$where['a.is_fx'] = 1;
		$user = db('info_user')
				->alias('a')
				->field('a.id,a.user_name,a.mobile,a.score,a.balance,b.count_balance,b.count')
				->join("$score b",'a.id=b.u_id','LEFT')
				->where($where)
				->order("b.count desc")
				->paginate(10,false,['query'=>request()->param()]);
		$this->assign('list',$user);
		$this->assign('empty','<span class="empty">没有数据</span>');
		if($this->request->isAjax()){
			return $this->fetch('ajax_index');
		}
		return $this->fetch();
	}
	
	//赏金明细列表
	public function money_reward(){
		$list = db('log_user_score')->where('order_type',14)
				->order('add_time desc')
				->paginate(10,false,['query'=>request()->param()]);
		$this->assign('list',$list);
		$this->assign('empty','<span class="empty">没有数据</span>');
		return $this->fetch();
	}
	
	//总鼓励金账户
	public function count_balance(){
		$list = db('admin_charge')
				->alias('a')
				->join('info_user b','a.user_id = b.id','LEFT')
				->field('a.*,b.user_name')
				->where('type',5)
				->order('add_time desc')
				->paginate(10,false,['query'=>request()->param()]);
		$this->assign('list',$list);
		
		$count_reward = db('admin_charge')->where('type',5)->sum('balance'); 
		$this->assign('count_reward',$count_reward);
		$this->assign('empty','<span class="empty">没有数据</span>');
		return $this->fetch();
	}
}
	
?>